<?php 
	//获取分类名
	function getCateName($id)
	{
		if($id==0){
			return '顶级分类';
		}
		$info = DB::table('shop_cates')->where('id',$id)->first();
		return $info->name;
	}
	
	//通过地区 id 获取地区名
	function getAreaNameById($id)
	{	
		if(is_array($id)){
			$area = [];
			foreach($id as $k=>$v){
				$area[] = DB::table('areas')->where('areaid',$v->areaid)->orderBy('areaid')->select('areaid','areaname')->first();
			}
		}else{
			$area = DB::table('areas')->where('areaid',$id)->select('areaname')->first()->areaname;
		}
		return $area;
	}

	//传入状态 获取收货地址
    function getAddress($sta)
    {	
    	//            0            1            2        3          4         5
        $status = ['待付款','已付款/未发货','已发货','订单完成','已评价','关闭订单'];
        return $status[$sta];
    }

	// 获取商品总价 订单id
    function total($id)
    {
        //订单金额
        $goods = DB::table('shop_ordgoods')->where('shop_ordgoods.order_id',$id)
        ->join('shop_goods','shop_ordgoods.goods_id','=','shop_goods.id')
        ->select('shop_goods.price','shop_ordgoods.num')->get();
        // dd($goods);
        $tp = 0;
        foreach($goods as $k=>$v){
            $price = $v->price;
            $num = $v ->num;
            $gprice = $price * $num;
            //获取总价
            $tp += $gprice; 
        }
        return $tp;
    }

    //获取 当前 用户的默认地址id
    function getDefaultAddr()
    {
        $defAddr_id = DB::table('shop_users')->where('id',session('id'))->select('defaultAddr_id')->first()->defaultAddr_id;
        return $defAddr_id;
    }

    //获取当前用户名 通过id
    function getUsername()
    {
        $username = DB::table('shop_users')->where('id',session('id'))->select('username')->first()->username;
        return $username;
    }

    //获取当前用户头像 通过id
    function getProfile()
    {
        $profile = DB::table('shop_users')->where('id',session('id'))->select('profile')->first()->profile;
        return $profile;
    }

    // 删除当前的用户名
    function delUsername(Request $request)
    {
        dd($request->input('id'));
        session()->forget('id');
        redirect('/');
    }

    // function dealPath($request)
    // {
    // 	// 处理图像
    //     if($request->hasfile('path')){
    //         $d = [];
    //         // 获取所有的文件对象
    //         $files=$request->file('path');
    //         foreach ($files as $k => $v) {
    //             $fileName = time().rand(100000,999999);
    //             $suffix = $v->getClientOriginalExtension();
    //             $fileName = $fileName.'.'.$suffix;
    //             $dir = './Uploads/comments/'.date('Ymd').'/';
    //             $v->move($dir,$fileName);
    //             // 拼接OK的图片路径(绝对路径)
    //             $tmp['path'] = trim($dir.$fileName,'.');
    //             $d[] = $tmp['path'];
    //         }
    // 	}else{
    // 		$d = null;
    // 	}
    // 	return $d;
    // }
 ?>